#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int N = 1e5 + 10;
int h[N], e[N], w[N], ne[N];
int index;
int dis[N], flag[N];
int cnt[N];
int m, n;
void add(int a, int b, int c)
{
	w[index] = c;
	e[index] = b;
	ne[index] = h[a];
	h[a] = index++;
}
bool spfa()
{
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		flag[i] = 1;
		q.push(i);
	}
	while (q.size()) {
		int temp = q.front();
		q.pop();
		flag[1] = 0;
		for (int i = h[temp]; i != -1; i = ne[i]) {
			int j = e[i];
			if (dis[j] > dis[temp] + w[i]) {
				dis[j] = dis[temp] + w[i];
				cnt[j] = cnt[temp] + 1;
				if (cnt[j] >= n) {
					return 1;
				}
				if (!flag[j]) {
					q.push(j);
					flag[j] = 1;
				}
			}
		}
	}
	return 0;
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	while (m--) {
		int a, b, c;
		cin >> a >> b >> c;
		add(a, b, c);
	}
	if (spfa()) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
	return 0;
}